package com.itlong.cloud.controller.finance;

import com.itlong.cloud.POJO.DTO.operate.OperateWeChatDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.operate.OperateWeChatVO;
import com.itlong.cloud.abstracts.BaseController;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.user.property.IPropertyWeChatServiceClient;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.page.Page;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      运营微信支付相关控制器
 * </desc>
 *
 * @createDate 2019/10/23
 */
@RestController
@RequestMapping("/finance/weChatPay")
public class OperateWeChatController extends BaseController {

    private static final Logger LOG = LoggerFactory.getLogger(OperateWeChatController.class);

    @Autowired
    private IPropertyWeChatServiceClient iPropertyWeChatServiceClient;

    /**
     * <desc>
     *      查询开通微信支付的所有项目及详细信息
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/10/23
     */
    @AuthAccessRequired
    @ResponseBody
    @PostMapping(path = "/getWeChatPayPage")
    public Object getWeChatPayPage(){
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            OperateWeChatDTO operateWeChatDTO = HttpProtocolUtil.parseRequestParamToDTO(OperateWeChatDTO.class, request);
            if (operateWeChatDTO == null) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            Page<OperateWeChatVO> page = iPropertyWeChatServiceClient.getWeChatPayPage(operateWeChatDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), page);
        } catch (Exception e) {
            throw new DataAccessException("【运营-微信支付管理getWeChatPayPage】查询开通微信支付的所有项目及详细信息失败",e);
        }
    }

}
